//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

import React from "react";
import { observer } from 'mobx-react';
import { useStores } from "@/hooks";
import { useHistory } from "react-router-dom";
import { APP_ORG_MANAGER_PATH, APP_PROJECT_MANAGER_PATH, DATA_VIEW_PATH, PUB_RES_PATH, WORKBENCH_PATH } from "@/utils/constant";
import { Space } from "antd";
import { open as shell_open } from '@tauri-apps/api/shell';
import s from "./WelcomeInfo.module.less";

const WelcomeInfo = () => {
    const history = useHistory();

    const appStore = useStores("appStore");
    const userStore = useStores("userStore");

    const getJoinToName = () => {
        const tmpList = [] as string[];
        if (appStore.vendorCfg?.ability.enable_project && userStore.userInfo.featureInfo.enable_project) {
            tmpList.push("项目");
        }
        if (appStore.vendorCfg?.ability.enable_org && userStore.userInfo.featureInfo.enable_org) {
            tmpList.push("团队");
        }
        return tmpList.join("/");
    };

    return (
        <div className={s.welcome_wrap}>
            <h1>欢迎使用<b>{appStore.vendorCfg?.layout.app_name ?? ""}</b>!</h1>
            {appStore.vendorCfg?.layout.vendor_intro == "" && (
                <p>
                    <b>{appStore.vendorCfg?.layout.app_name ?? ""}</b>通过有效整合研发过程中的多种生产要素，从而提高研发人员{appStore.vendorCfg?.ability.enable_project && "和团队"}的研发效能。
                </p>
            )}
            {appStore.vendorCfg?.layout.vendor_intro != "" && (
                <div dangerouslySetInnerHTML={{ __html: appStore.vendorCfg?.layout.vendor_intro ?? "" }} />

            )}
            <p>
                对于研发个体，<b>{appStore.vendorCfg?.layout.app_name ?? ""}</b>提供了<a onClick={e => {
                    e.stopPropagation();
                    e.preventDefault();
                    history.push(`${WORKBENCH_PATH}?tab=localRepo`);
                }}>本地Git仓库管理</a>
                {appStore.vendorCfg?.work_bench.enable_minapp && (
                    <>
                        ，还提供了大量研发辅助工具，您可以在<a onClick={e => {
                            e.stopPropagation();
                            e.preventDefault();
                            history.push(`${WORKBENCH_PATH}?tab=userApp`);
                        }}>微应用</a>中访问这些辅助工具{userStore.sessionId == "" && (appStore.vendorCfg?.account.inner_account || appStore.vendorCfg?.account.external_account) && (
                            <>(<a onClick={e => {
                                e.stopPropagation();
                                e.preventDefault();
                                userStore.showUserLogin = true;
                            }}>登录</a>后可访问更多功能)</>
                        )}
                    </>
                )}
                。
                {userStore.sessionId != "" && appStore.vendorCfg?.ability.enable_dataview && userStore.userInfo.featureInfo.enable_data_view && (
                    <>
                        同时我们还提供了<a
                            onClick={e => {
                                e.stopPropagation();
                                e.preventDefault();
                                history.push(DATA_VIEW_PATH);
                            }}>数据视图</a>功能，让您可以更直观的查看外部系统数据。
                    </>
                )}
                {appStore.vendorCfg?.ability.enable_project && (
                    <>
                        <br />
                        <br />
                        <p>
                            对于研发团队，您可以使用项目功能来进行项目管理，项目沟通，风险预警，开发协作和知识沉淀。我们还提供了
                            <a
                                onClick={e => {
                                    e.stopPropagation();
                                    e.preventDefault();
                                    shell_open("https://marketplace.visualstudio.com/items?itemName=linksaas.local-api");
                                }}>vscode插件</a>，可以方便您在vscode中查看任务/缺陷/文档等项目数据。
                        </p>
                    </>
                )}
                <br />
                <p>
                    如果您在使用过程中遇到了任何问题，请向我们提供<a onClick={e => {
                        e.stopPropagation();
                        e.preventDefault();
                        appStore.showFeedBack = true;
                    }}>反馈</a>，我们会在第一时间修复问题。
                </p>
                <h1>功能入口</h1>
                <h2>研发个体</h2>
                <Space>
                    <a onClick={e => {
                        e.stopPropagation();
                        e.preventDefault();
                        history.push(`${WORKBENCH_PATH}?tab=localRepo`);
                    }}>本地仓库</a>
                    {appStore.vendorCfg?.work_bench.enable_minapp == true && (
                        <a onClick={e => {
                            e.stopPropagation();
                            e.preventDefault();
                            history.push(`${WORKBENCH_PATH}?tab=userApp`);
                        }}>微应用</a>
                    )}
                </Space>
                {userStore.sessionId != "" && (
                    <>
                        {((appStore.vendorCfg?.ability.enable_project && userStore.userInfo.featureInfo.enable_project) ||
                            (appStore.vendorCfg?.ability.enable_org && userStore.userInfo.featureInfo.enable_org)) && (
                                <>
                                    <h2>研发团队</h2>
                                    <div>
                                        <a onClick={e => {
                                            e.stopPropagation();
                                            e.preventDefault();
                                            appStore.showJoinModal = true;
                                        }}>加入{getJoinToName()}</a>
                                    </div>
                                    {(appStore.vendorCfg?.ability.enable_project && userStore.userInfo.featureInfo.enable_project) && (
                                        <div>
                                            <Space>
                                                <a onClick={e => {
                                                    e.stopPropagation();
                                                    e.preventDefault();
                                                    appStore.showCreateOrJoinProject = true;
                                                }}>创建项目</a>
                                                <a onClick={e => {
                                                    e.stopPropagation();
                                                    e.preventDefault();
                                                    history.push(APP_PROJECT_MANAGER_PATH);
                                                }}>项目管理</a>
                                            </Space>
                                        </div>
                                    )}
                                    {(appStore.vendorCfg?.ability.enable_org && userStore.userInfo.featureInfo.enable_org) && (
                                        <Space>
                                            <a onClick={e => {
                                                e.stopPropagation();
                                                e.preventDefault();
                                                appStore.showCreateOrJoinOrg = true;
                                            }}>创建团队</a>
                                            <a onClick={e => {
                                                e.stopPropagation();
                                                e.preventDefault();
                                                history.push(APP_ORG_MANAGER_PATH);
                                            }}>团队管理</a>
                                        </Space>
                                    )}
                                </>
                            )}
                    </>
                )}
                {appStore.vendorCfg?.ability.enable_pubres && (
                    <>
                        <h2>公共资源</h2>
                        <Space>
                            <a onClick={e => {
                                e.stopPropagation();
                                e.preventDefault();
                                history.push(`${PUB_RES_PATH}?tab=ideaStore`);
                            }}>知识点仓库</a>
                            <a onClick={e => {
                                e.stopPropagation();
                                e.preventDefault();
                                history.push(`${PUB_RES_PATH}?tab=swStore`);
                            }}>常用软件</a>
                        </Space>
                    </>
                )}
            </p>
        </div>
    );
};

export default observer(WelcomeInfo);